#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <algorithm>

namespace pot {

void GenSignedIntegers(int A[], int n) {
  srand(static_cast<unsigned int>(time(NULL)));
  int pivot = RAND_MAX / 2;
  for (int i = 0; i < n; ++i) A[i] = rand() - pivot; 
}

float rand_percents() {
  return (rand() % 100) / 100.f;
}

void GenIntegers(int A[], int k, int n) {
  float s = 0;
  float m = float(n) / k;

  for (int i = 0; i < k; ++i, s += m) {
    A[i] = int(s + m * rand_percents());
  }

  for (int i = 0; i < k; ++i) {
    int j = rand() % k;
    std::swap(A[i], A[j]);
  }
}

/* 
 * generate random numbers in ascending order
 */
void GenIntegersKnuth(int A[], int k, int n) {  
  for (int i = 0; i < n; ++i) {
    if ((rand() % (n - i)) < k) {
      A[--k] = i;      
    }
  }  
}

void RandomTest() {
  int ks[] = { 1000, 10000, 100000, 999999 };
  const int n = 1000000; 
  int *A = new int[n];
 /* for (int i = 1; i < 10000; ++i) {
    pot::GenIntegersKnuth(A, i, n);
  }*/
  delete[] A;
}

char GenAlaph() { return 'a' + rand() % 26; }

int HashAlpha(char c) {
  return 1 << (c - 'a');
}

int HashWord(const char *word) {
  int val = 0;
  while (*word != '\0') {
    val |= HashAlpha(*word);
    ++word;
  }
  return val;
}

} // pot